<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .bg{
            background-color: blue;
        }
        #con{
            width: 400px;
            height: 300px;
            border: 5px solid red;
            padding: 30px;
        }
        #con img{
            width:100%;
        }
    </style>
</head>
<body>
    <div id="con" class="list">
        <img src="./images/1.png" width="100%">
    </div>
</body>
<script>
    var con = document.getElementsByClassName("list");
    con[0].onmouseover = function(){
        var classStr = this.className;
        var classArr = classStr.split(" ");
        if(classArr.indexOf("bg") >=0 ){
            return ;
        }else{
            this.className = this.className + " bg";
        }
    }
    con[0].onmouseout = function(){
        var classStr = this.getAttribute("class");
        var classArr = classStr.split(" ");
        var index = classArr.indexOf("bg");
        if(index>=0){
            classArr.splice(index,1);
            var str = classArr.join(" ");
            this.setAttribute("class",str);
        }else{
            return;
        }
    }
</script>
</html>